import { ECSSystem } from "../../../3rd/ECS/ECSSystem";
import { ecsclass } from "../../../3rd/ECS/__private";
import { Vector3 } from "../../../Bridge/Vec";
import { PlayerComponent, StarComponent } from "../components/NoDataComponent";
import { PositionComponent } from "../components/PositionComponent";
import { RenderNodeComponent } from "../components/RenderNodeComponent";

ecsclass("EatSystem")
export class EatSystem extends ECSSystem
{
    start()
    {
        
    }

    update()
    {
        var playerCom = this.ecs.components.get(PlayerComponent);
        var starsCom = this.ecs.components.all(StarComponent);
        var playerPos = this.ecs.entities.get(playerCom.entityId).getComponent(PositionComponent).pos;

        starsCom.forEach(element => {
            var starEntity = this.ecs.entities.get(element.entityId);
            var starPosition = starEntity.getComponent(PositionComponent).pos

            if (Vector3.Distance(starPosition,playerPos)<0.5)
            {
                starEntity.getComponent(RenderNodeComponent).node.SetActive(false);
            }

        });
    }

    
}